package com.lang;

import org.junit.Test;

import java.io.*;
import java.util.Enumeration;
import java.util.Properties;
import java.util.Set;

/**
 *
 * Created by yangliwei on 2017/7/24.
 */
public class SystemDemo {

    //查看所有的系统属性
    @Test
    public void testAllProperties(){
        Properties properties = System.getProperties();
        Enumeration enums = properties.propertyNames();
        while(enums.hasMoreElements())
            System.out.println(enums.nextElement());
        System.out.println("------------------------------;------------");
        Set<String> set = properties.stringPropertyNames();
        for(String temp :set){
            System.out.println(temp +" : "+System.getProperty(temp));
        }

    }

    @Test
    public void testLoadLib(){
        System.loadLibrary("net");
    }

    /**
     * 更换输出
     */
    @Test
    public void testOut() throws FileNotFoundException {
//        使用新的输出
        String filePath = "./abc";
        PrintStream out = new PrintStream(new File(filePath));
        System.setOut(out);
        System.out.println("aaaaaaaaaaa");

//        换回原来的输出
        FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);
        System.setOut(new PrintStream(new BufferedOutputStream(fdOut, 128), true));
        System.out.println("bbbbbbb");

    }
}
